import { api_getDictList } from '@/apis'
import { defineStore } from 'pinia'

export const useDictStore = defineStore('dict', () => {

  const dictMap = ref({})

  function getDictByGroupFromCache (group) {
    return this.dictMap[group] || []
  }

  function setDictValueByGroup (group, value) {
    this.dictMap[group] = value
  }

  async function getDictList () {
    try {
      const _dict = await api_getDictList()
      this.dictMap = _dict
    } catch (error) {

    }
  }

  return {
    dictMap,
    getDictByGroupFromCache,
    setDictValueByGroup,
    getDictList
  }

}, {
  persistent: {
    enabled: true,
    storage: sessionStorage
  }
})
